//
//  ChongZhiViewController.m
//  AnnCar_user
//
//  Created by LiBenCan on 17/10/25.
//  Copyright © 2017年 LiBenCan. All rights reserved.
//

#import "ChongZhiViewController.h"
#import "RechargeCell.h"
@interface ChongZhiViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableV;
@property (nonatomic,assign)NSInteger chooseNumber;//选择的行数
@property (nonatomic,strong)UIButton *rechargeBtn;//充值按钮
@end

@implementation ChongZhiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _chooseNumber = -1;
    [self initTitleWithTitle:@"充值"];
    [self.view addSubview:self.tableV];
    [self.view addSubview:self.rechargeBtn];
}
-(UITableView *)tableV//创建tableView
{
    if (!_tableV) {//_table不存在
        _tableV = [[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREENW, SCREENH-64-44*screenW_6) style:UITableViewStyleGrouped];
        _tableV.rowHeight = 75*screenW_6;
        _tableV.backgroundColor = backColor;
        _tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableV.showsVerticalScrollIndicator = NO;
        _tableV.delegate = self;
        _tableV.dataSource = self;
        //注册Cell
        //        [_tableV registerClass:[AroundCell class] forCellReuseIdentifier:AroundCellID];
        //        //刷新
        //        _tableV.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        //            _PageNumber = 1;
        //            [self getListData:YES];
        //            [self addLunBoRequest:_cityName];;
        //        }];
        //        //加载
        //        _tableV.mj_footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
        //            _PageNumber++;
        //            [self getListData:NO];
        //        }];
    }
    return _tableV;
}
#pragma TableViewDegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5*screenW_6;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 5*screenW_6;
    }
    return 0.0000001;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //充值的Cell
    RechargeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RechargeCell"];
    if (cell == nil) {
        cell = [[RechargeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"RechargeCell"];
    }
    [cell setDataDic:nil];
    cell.chooseImage.image =  [UIImage imageNamed:indexPath.section == _chooseNumber?@"circle_select":@"circle"];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //选择的行 再刷新
    _chooseNumber = indexPath.section;
    [_tableV reloadData];
}

//充值按钮
-(UIButton *)rechargeBtn
{
    if (!_rechargeBtn) {
        
        _rechargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rechargeBtn.frame = CGRectMake(0, SCREENH-64-44*screenW_6, SCREENW, 44*screenW_6);
        [_rechargeBtn setTitle:@"确认充值" forState:UIControlStateNormal];
        [_rechargeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rechargeBtn.backgroundColor = blueColor;
        [_rechargeBtn setImage:[UIImage imageNamed:@"recharge_2"] forState:UIControlStateNormal];
        [_rechargeBtn setImageEdgeInsets:UIEdgeInsetsMake(12*screenW_6,SCREENW/2-50*screenW_6,12*screenW_6,SCREENW/2-30*screenW_6)];
        [_rechargeBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,SCREENW/2-40*screenW_6,0,SCREENW/2-60*screenW_6)];
        [_rechargeBtn addTarget:self action:@selector(rechargeSelect) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _rechargeBtn;
}

//选择充值
-(void)rechargeSelect
{
    [HudHelper showProgressHudWithMessage:@"" toView:self.view];
    if (_chooseNumber<0) {
        [TomamaUI creatAlertWithTarget:self message:@"请选择充值金额" timeInterval:2];
        [HudHelper hideHudToView:self.view];
        return;
    }
}
@end
